package com.example.test;

import org.openhitls.crypto.SM3;
import org.junit.Test;
import static org.junit.Assert.*;

public class SM3Test {
    
    @Test
    public void testSM3SingleShot() {
        String message = "Hello, SM3!";
        byte[] hash = SM3.hash(message.getBytes());
        
        // Print hash in hex
        System.out.println("Hash of '" + message + "':");
        for (byte b : hash) {
            System.out.printf("%02x", b);
        }
        System.out.println();
        
        // Verify hash length
        assertEquals(32, hash.length);
    }
    
    @Test
    public void testSM3Incremental() {
        SM3 sm3 = new SM3();
        String part1 = "Hello, ";
        String part2 = "SM3!";
        
        sm3.update(part1.getBytes());
        sm3.update(part2.getBytes());
        byte[] incrementalHash = sm3.doFinal();
        
        // Compare with single-shot hash
        byte[] singleHash = SM3.hash((part1 + part2).getBytes());
        
        System.out.println("Incremental hash:");
        for (byte b : incrementalHash) {
            System.out.printf("%02x", b);
        }
        System.out.println();
        
        assertArrayEquals(singleHash, incrementalHash);
    }
    
    @Test
    public void testEmptyString() {
        byte[] hash = SM3.hash(new byte[0]);
        assertEquals(32, hash.length);
        
        System.out.println("Hash of empty string:");
        for (byte b : hash) {
            System.out.printf("%02x", b);
        }
        System.out.println();
    }
}
